#include "file_list.h"
#include <dirent.h>
#include <iostream>

FileList::FileList (const char* directory)
{
  files_.clear ();
  if (directory)
    getFilesInDirectory (directory);
  else
    std::cout << "directory is NULL" << std::endl;
}

FileList::~FileList ()
{

}

int FileList::getFilesInDirectory (std::string directory)
{
  DIR *dp;
  struct dirent *dirp;
  if ((dp  = opendir (directory.c_str())) == NULL)
    {
      std::cout << "Error(" << errno << ") opening " << directory << std::endl;
      return errno;
    }
  
  while ((dirp = readdir (dp)) != NULL)
    files_.push_back (std::string (dirp->d_name));

  closedir (dp);
  return 0;
}

vector<std::string>& FileList::getFiles ()
{
  return files_;
}
